<template>
	<div>
		<el-button @click="download">单文件下载</el-button>
	</div>
</template>

<script>
import { BASE_URL, $get, $post, $POST } from '@/plugin/request.js';
import {downloadFileByBlob} from '@/utils/object.js'
export default {
	name: 'AjaxDownloadDemo',
	methods: {
		download() {
			$POST('/user/getResource',null,{
				headers: {
				    'Accept': 'image/jpeg;*/*'
				},
			}).then(res => {
				console.log(res);
				let contentDisposition=res.headers['content-disposition']
				let fileName=null;
				if(contentDisposition){
					fileName=contentDisposition.match(/.*filename=(.*)/)[1]
				}
				downloadFileByBlob(res.data,fileName)
			});
		}
	}
};
</script>

<style></style>
